package io.renren.modules.hospital.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.hospital.entity.EmrHzInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import io.renren.modules.hospital.entity.EmrGhInfoEntity;
import io.renren.modules.hospital.service.EmrGhInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * @author starry
 * @email 2495646304@qq.com
 * @date 2024-01-29 18:00:42
 */
@RestController
@RequestMapping("hospital/emrghinfo")
@Api(value = "EMR挂号接口", tags = "EMR挂号接口")
public class EmrGhInfoController {
    @Autowired
    private EmrGhInfoService emrGhInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("列表")
    //@RequiresPermissions("hospital:emrghinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        int currentPage = Integer.parseInt((String) params.get("page"));
        int pageSize = Integer.parseInt((String) params.get("limit"));
        List<EmrGhInfoEntity> list = emrGhInfoService.getAllGhList((currentPage - 1) * pageSize, pageSize);
//        System.out.println(list);
        Integer size = emrGhInfoService.getAllNum();
        PageUtils page = new PageUtils(list, size, pageSize, currentPage);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{emrGhId}")
    @ApiOperation("信息")
    //@RequiresPermissions("hospital:emrghinfo:info")
    public R info(@PathVariable("emrGhId") Integer emrGhId) {
        EmrGhInfoEntity emrGhInfo = emrGhInfoService.getById(emrGhId);

        return R.ok().put("emrGhInfo", emrGhInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("新增一个挂号记录")
    //@RequiresPermissions("hospital:emrghinfo:save")
    public R save(@RequestBody EmrGhInfoEntity emrGhInfo) {
        emrGhInfoService.save(emrGhInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改")
    //@RequiresPermissions("hospital:emrghinfo:update")
    public R update(@RequestBody EmrGhInfoEntity emrGhInfo) {
        emrGhInfoService.updateById(emrGhInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("删除")
    //@RequiresPermissions("hospital:emrghinfo:delete")
    public R delete(@RequestBody Integer[] emrGhIds) {
        emrGhInfoService.removeByIds(Arrays.asList(emrGhIds));

        return R.ok();
    }


    @GetMapping("/getGhListByHzId")
    @ApiOperation("根据患者id查找该患者的所有挂号记录")
    public R getGhListByHzId(Integer hzId) {
        List<EmrGhInfoEntity> ghInfoEntities = emrGhInfoService.getGhListByHzId(hzId);
        return R.ok().put("ghList", ghInfoEntities);
    }


    /**
     * 根据医生id查找该医生的当天所有挂号记录
     *
     * @param ysId 医生编号
     * @return 挂号记录列表
     */
    @GetMapping("/getGhListByYsId")
    @ApiOperation("根据医生id查找该医生的当天所有挂号记录")
    public R getGhListByYsId(Integer ysId) {
        List<EmrGhInfoEntity> ghInfoEntities = emrGhInfoService.getGhListByYsId(ysId);
        return R.ok().put("ghList", ghInfoEntities);
    }

}
